package zwh.mall.entity.pojo;

import java.io.Serializable;

/**
 * 返回到前端的状态数据信息
 * @author 97506
 */
public class ResultData<T> implements Serializable {
    /**
     * 成功状态码
     */
    public static final int SUCCESS = 0;
    /**
     * 失败状态码
     */
    public static final int FAIL = 1;
    /**
     * 没有权限
     */
    public static final int NO_PERMISSION = 2;

    public static final String NOT_LOGIN = "未登录";
    public static final String NOT_PERMISSION = "没有权限";
    public static final String SUCCESS_MSG = "成功";
    public static final String FAIL_MSG = "失败";

    private String message = null;
    private int state;
    /**
     * 返回的数据
     */
    private T data;

    public ResultData() {
        super();
    }

    public ResultData(T data) {
        super();
        this.data = data;
    }

    /**
     * 包装异常信息
     *
     * @param e
     */
    public ResultData(Throwable e) {
        super();
        this.message = e.getMessage();
        this.state = FAIL;
    }

    public ResultData(String message) {
        super();
        this.message = message;
        this.state = FAIL;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultBean{" +
                "message='" + message + '\'' +
                ", state=" + state +
                ", data=" + data +
                '}';
    }
}
